import React, { Component } from 'react'
import { Relax } from 'iflux2'
import noop from 'util/noop'
import NewsItem from './news-item'
const iDisplayLength = 12;//分页 一页的个数

import { Pagination, Button } from 'antd';
import NoData from 'uikit/no-data';

@Relax
export default class NewsList extends Component {

    static defaultProps = {
        tabs: '',
        curPage: 1,
        newsList: '',// 图文信息列表 Map类型
        _initNewsList: noop,
        _addNews: noop,
        _editNews: noop,
    };
    render() {
        const { tabs, curPage, newsList, _addNews, _editNews, _initNewsList } = this.props;
        let newsItems = newsList.get('item').map(item => {
            return <NewsItem key={item.get('media_id')} item={item} />
        });
        const { total_count } = newsList.toJS();
        return (
            <div className="newsView">
                <Button type="primary" size="large" onClick={_addNews}>{`新建${tabs == 'adNews' ? '高级' : ''}图文`}</Button>
                <div className="newsList">
                    <div className="container">
                        <ul className="news">
                            {newsItems}
                        </ul>
                    </div>
                    {
                        newsItems.size
                            ? <Pagination className="news-pagination"
                                current={curPage}
                                pageSize={iDisplayLength}
                                defaultCurrent={curPage}
                                defaultPageSize={iDisplayLength}
                                total={total_count}
                                onChange={_initNewsList} />
                            : <NoData content={`您还没有${tabs == 'adNews' ? '高级' : ''}图文消息`} />
                    }
                </div>
            </div>
        )
    }
}